<?php
/*
 * stat.php
 */
?>
<!doctype html>
<html lang="fr">
    <head>
        <meta charset="utf-8">
        <title>Statistiques des newsletters</title>
        <link type="text/css" rel="stylesheet" href="bootstrap.min.css">
        <script type="text/javascript" src="jquery-1.11.0.min.js"></script>
        <script type="text/javascript" src="bootstrap.min.js"></script>
    </head>
    <body>
        <div class="content-body">
            <div class="tabbable"> 
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#email" data-toggle="tab">Statistiques par Email</a></li>
                    <li><a href="#newsletter" data-toggle="tab">Statistiques par Newsletter</a></li>
                    <li><a href="#list" data-toggle="tab">Liste des Newsletters</a></li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane active" id="email">
                        <!-- AJAX -->
                        <?php //include './stat_email.php' ?>
                        <img src='../img/loading.gif'>
                    </div>
                    <div class="tab-pane" id="newsletter">
                        <!-- AJAX -->
                        <?php //include './stat_newsletter.php' ?>
                        <img src='../img/loading.gif'>
                    </div>
                    <div class="tab-pane" id='list'>
                        <a href='newsletters.php'>Aller à la liste des newsletters</a>
                    </div>
                </div>
            </div>
        </div>

        <style type='text/css'>
            .content-body{
                padding: 5px;
            }
            .tab-content{
                padding: 5px;
                border: solid 1px #cccccc;
                border-top: none;
            }
        </style>

        <script type="text/javascript">
            $(function() {
                // Email
                $(document).on('click', '.reorder-email', function(e) {
                    e.preventDefault();
                    var field = $(this).attr('data-field');
                    var order = $(this).attr('data-order');
                    var $ajax = $.ajax({
                        type: 'post',
                        url: 'stat_email.php',
                        data: '&field=' + field + '&order=' + order
                    });
                    $ajax.done(function(data) {
                        $('#email').html(data);
                    });
                });
                // Newsletter
                $(document).on('click', '.reorder-news', function(e) {
                    e.preventDefault();
                    var field = $(this).attr('data-field');
                    var order = $(this).attr('data-order');
                    var $ajax = $.ajax({
                        type: 'post',
                        url: 'stat_newsletter.php',
                        data: '&field=' + field + '&order=' + order
                    });
                    $ajax.done(function(data) {
                        $('#newsletter').html(data);
                    });
                });

                var $email = $.ajax({
                    type: 'post',
                    url: 'stat_email.php'
                    //data: '&field=' + field + '&order=' + order
                });
                $email.done(function(data) {
                    $('#email').html(data);
                });
                var $new = $.ajax({
                    type: 'post',
                    url: 'stat_newsletter.php'
                    //data: '&field=' + field + '&order=' + order
                });
                $new.done(function(data) {
                    $('#newsletter').html(data);
                });
            });
        </script>

    </body>
</html>
